package com.dmai.aiet.common.base;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class Result<T> {
    private Integer code;

    private String msg;

    private T data;

    /**
     * 成功统一响应格式
     *
     * @param
     * @param <T>
     * @return
     */
    public static <T> Result<T> success() {
        Result<T> apiResponse = new Result<>(200, "成功", null);
        return apiResponse;
    }

    /**
     * 成功统一响应格式
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> success(T data) {
        Result<T> apiResponse = new Result<>(200, "成功", data);
        return apiResponse;
    }

    /**
     * 失败统一响应格式
     *
     * @param code
     * @param message
     * @param <T>
     * @return
     */
    public static <T> Result<T> fail(Integer code, String message) {
        return new Result<>(code, message, null);
    }
}
